home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / VideoToolbox 95.04.18 / Demos / Quitter.c < prev    next >
C/C++ Source or Header  |  1995-01-11  |  3KB  |  66 lines

  1. /*
  2. Quitter.c
  3.  
  4. Kill a program on a local or remote computer. Works by sending an AppleEvent.
  5. Unfortunately, it appears that Apple doesn't consider active desk accessories
  6. as "processes" to which one can send an AppleEvent. 
  7.  
  8. It is essential that the HighLevelEvent-Aware bit be set in the SIZE resource; 
  9. use the menu item Project:SetProjectType:SIZE Flags.
  10.  
  11. At present this has nothing at all to do with the rest of the VideoToolbox, but
  12. David Brainard and I have been discussing the idea of a stand-alone VideoToolbox
  13. application that accepts AppleEvents commanding it to produce visual stimuli. 
  14.  
  15. HISTORY:
  16. 3/5/93 dgp wrote it
  17. 3/9/93    dgp got it to work, by setting the HighLevelEvent-Aware bit, as instructed
  18. by Larry Harris, 76150,1027, a friendly fellow programmer on CompuServe.
  19. 4/17/93    dgp    #include VideoToolbox.h for PrintfExit().
  20. 12/15/93 dgp Go away quietly if user hits Cancel.
  21. 7/29/94 dgp Eliminated use of "#s" printf format, since it's not supported by
  22.             Metrowerks CodeWarrior C.
  23. 9/5/94 dgp removed assumption in printf's that int==short.
  24. */
  25. #include "VideoToolbox.h"
  26. #include <stdarg.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <AppleEvents.h>
  30.  
  31. void main(void)
  32. {
  33.     int error;
  34.     unsigned char prompt[]="\pChoose a program to quit.";
  35.     PortInfoRec portInfo;
  36.     TargetID targetID;
  37.     AEAddressDesc target;
  38.     AppleEvent appleEvent,reply;
  39.     AESendMode sendMode;
  40.     long value;
  41.  
  42.     MaximizeConsoleHeight();
  43.     printf("Welcome to Quitter.\n");
  44.     Gestalt(gestaltAppleEventsAttr,&value);
  45.     if(!(value&(1<<gestaltAppleEventsPresent)))PrintfExit("Sorry, I need AppleEvents.\n");
  46.     PPCInit();
  47.     // Select target through dialog with user.
  48.     error=PPCBrowser(prompt,NULL,0,&targetID.location,&portInfo,NULL,NULL);
  49.     if(error==-128)abort();    // User pressed Cancel.
  50.     if(error)PrintfExit("PPCBrowser error %d\n",error);
  51.     targetID.name=portInfo.name;
  52.     error=AECreateDesc(typeTargetID,(Ptr)&targetID,sizeof(targetID),&target);
  53.     if(error)PrintfExit("AECreateDesc error %d\n",error);
  54.     error=AECreateAppleEvent(kCoreEventClass,kAEQuitApplication,&target
  55.         ,kAutoGenerateReturnID,kAnyTransactionID,&appleEvent);
  56.     if(error)PrintfExit("AECreateAppleEvent error %d\n",error);
  57.     error=AEDisposeDesc(&target);
  58.     sendMode=kAENoReply+kAENeverInteract+kAEDontReconnect;
  59.     error=AESend(&appleEvent,&reply,sendMode,kAENormalPriority
  60.         ,kAEDefaultTimeout,NULL,NULL);
  61.     if(error)PrintfExit("AESend error %d\n",error);
  62.     error=AEDisposeDesc(&appleEvent);
  63.     if(error)PrintfExit("AEDisposeDesc error %d\n",error);
  64.     printf("Done. “%s” has been asked to quit.\n",p2cstr(targetID.name.name));
  65. }
  66.